#include "widget.h"
#include "./ui_widget.h"
#include <QThread>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    connect(ui->BtnStartThread, SIGNAL(clicked()), this, SLOT(sltStartThread0()));
}

Widget::~Widget()
{
    delete ui;
}

void Widget::sltStartThread0()
{
    if(pWorker != nullptr)
    {
        qDebug() << "\npWorker != nullptr";
        pWorker = nullptr;
    }

    pWorker = new Worker();
    QThread *thread = new QThread();
    pWorker->moveToThread(thread);
    connect(thread, SIGNAL(started()), pWorker, SLOT(doWork()));
    connect(pWorker, SIGNAL(workFinished()), thread, SLOT(quit()));
    connect(pWorker, SIGNAL(workFinished()), pWorker, SLOT(deleteLater()));
    connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
    thread->start();
}

void Widget::sltStopThread0()
{

}
